<?php
namespace app\admin\controller;

use app\admin\api\ConferencePaperFull;
use app\admin\controller\Permissions;


/**
 * 会议站--论文全文管理
 */
class Conferpaperfull extends  Permissions{

    /**
     * 获取论文摘要列表
     */
    public function list($sid,$paper_id){

        //换区网站token
        $token = getapptoken($sid);

        $data = new ConferencePaperFull();

        //接收数据
        if($this->request->isPost()){

            $post = $this->request->post();

            $res = $data->fullList($token,$paper_id,$post);
            $site = $res->items;

            if(empty($site)){
                $this->assign('intrs',-1);
                $this->assign('sid',$sid);
            }else{
                $intrs = getstandardpaperabstract($site);
                $intrs[0]['sid'] = $sid;
                return json($intrs);
            }
        }else{
            $fy['page'] = 1;
            $fy['limit'] = 10;

            $res = $data->fullList($token,$paper_id,$fy);
            $site = $res->items;

            if(empty($site)){
                $this->assign('intrs',-1);
                $this->assign('sid',$sid);
            }else{

                //列表总数
                $total = $res->meta->total;
                $intrs = getstandardpaperabstract($site);
                $intrs[0]['sid'] = $sid;

                $this->assign('sid',$sid);
                $this->assign('intrs',$intrs);
                $this->assign('total',$total);
            }
            return view();
//            var_dump($site);
        }
    }

    /**
     * 创建论文全文
     */

    public function create($sid){

        //获取站点语言
        $lang = getlang($sid);
        //获取当前时间错作为文件编号
        $time = date("Ymd-H-i-s");

        $this->assign('sid',$sid);
        $this->assign('lang',$lang);
        $this->assign('time',$time);

        return view();

    }

    public function add(){
        if($this->request->isPost()) {

            //接收站点数据
            $post = $this->request->post();
            $data['file_url'] = $post['file_url'];
            $sid = $post['sid'];

            //换区网站token
            $token = getapptoken($sid);

            $data2 = new ConferencePaperFull();
            $result = $data2->fullCreate( $data,$token);

            if ($result == 555){
                $this->success("提交成功");

            }else{
                $this->error("$result");
            }
        }
    }


    /**
     * 获取论文全文详情
     * @return [type] [description]
     */
    public function details($sid,$id){

        //换取网站token
        $token = getapptoken($sid);

        $data = new ConferencePaperFull();
        $res = $data->fullDetails($id,$token);

        //获取站点语言
        $lang = getlang($sid);

        $this->assign('sid',$sid);
        $this->assign('lang',$lang);
        $this->assign('intr',$res);
//        var_dump($res);
        return view();
    }


    /**
     * 更新论文全文
     */
    public function update(){
        if($this->request->isPost()) {

            $post = $this->request->post();
            $sid = $post['sid'];

            //换区网站token
            $token = getapptoken($sid);

            //接收数据
            $id = $post['id'];
            $data['file_url'] = $post['file_url'];

            $data2 = new ConferencePaperFull();
            $res = $data2->fullUpdate($id,$data,$token);

            if ($res == 555){
                $this->success("修改成功");
            }else{
                $this->error("$res");
            }
        }
    }

    /**
     * 删除论文全文
     */
    public function delete(){
        if ($this->request->isPost()) {

            //接收数据
            $post = $this->request->post();
            $id = $post['id'];
            $sid = $post['sid'];

            //换区网站token
            $token = getapptoken($sid);

            //请求接口
            $data = new ConferencePaperFull();

                $res = $data->fullDelete($id,$token);

            if ($res == 555) {
                $this->success("删除成功");

            } else {
                $this->error("$res");
            }
        }
    }

    public function statusfull($sid,$id,$es){

        //换区网站token
        $token = getapptoken($sid);

            if($es == 0){
                $data2 = new ConferencePaperFull();
                $res = $data2->fullreview($id,$token);
                if ($res == 555){
                    $this->success("修改成功");
                }else{
                    $this->error("$res");
                }
            }else if($es == 1){
                $data2 = new ConferencePaperFull();
                $res = $data2->fullpassed($id,$token);
                if ($res == 555){
                    $this->success("修改成功");
                }else{
                    $this->error("$res");
                }
            }else if($es == 2){
                $data2 = new ConferencePaperFull();
                $res = $data2->fullrefuse($id,$token);
                if ($res == 555){
                    $this->success("修改成功");
                }else{
                    $this->error("$res");
                }
            }else if($es == 3){
                $data2 = new ConferencePaperFull();
                $res = $data2->fullrevise($id,$token);
                if ($res == 555){
                    $this->success("修改成功");
                }else{
                    $this->error("$res");
                }
            }else{
                $this->error("状态不存在");
            }
    }

}